/*
 * Copyright ${.now?string("yyyy")} the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package ${config.packageName}.${config.classSuffix?lower_case};

<#if (config.useStateSupport)>import net.ymate.platform.core.beans.annotation.PropertyState;</#if>
import net.ymate.platform.core.persistence.annotation.Comment;
import net.ymate.platform.core.persistence.annotation.Default;
import net.ymate.platform.core.persistence.annotation.Property;
import net.ymate.platform.core.persistence.annotation.Readonly;
import net.ymate.platform.core.persistence.annotation.PK;
import net.ymate.platform.core.persistence.base.IEntityPK;

/**
 * ${entityInfo.name?cap_first}PK generated By EntityMojo on ${lastUpdateTime?string("yyyy/MM/dd HH:mm:ss")}
 *
 * @author YMP (https://www.ymate.net/)
 */
@PK
public class ${entityInfo.name?cap_first}PK implements IEntityPK {

    private static final long serialVersionUID = 1L;

<#list entityInfo.primaryKeys as field>
    <#if (field.columnName!"undefined") != "undefined">
    @Property(name = ${entityInfo.name?cap_first}<#if (config.useClassSuffix)>${config.classSuffix?cap_first}</#if>.FIELDS.${field.constVarName?upper_case}<#if (field.autoIncrement)>, autoincrement=true</#if><#if (field.nullable)>, nullable = false</#if><#if (!field.signed)>, unsigned = true</#if><#if (field.precision > 0)>, length = ${field.precision?string('#')}</#if><#if (field.scale > 0)>, decimals = ${field.scale}</#if>)<#if (field.defaultValue!"undefined") != "undefined">
    @Default("${field.defaultValue}")</#if><#if (field.remarks!"undefined") != "undefined">
    @Comment("${field.remarks}")</#if><#if (config.useStateSupport)>
    @PropertyState(propertyName = ${entityInfo.name?cap_first}<#if (config.useClassSuffix)>${config.classSuffix?cap_first}</#if>.FIELDS.${field.constVarName?upper_case})</#if><#if (field.readonly)>
    @Readonly</#if></#if>
    private ${field.varType} ${field.varName};

</#list>

    public ${entityInfo.name?cap_first}PK() {
    }

    public ${entityInfo.name?cap_first}PK(<#list entityInfo.primaryKeys as field>${field.varType} ${field.varName}<#if field_has_next>, </#if></#list>) {
    <#list entityInfo.primaryKeys as field>
        this.${field.varName} = ${field.varName};
    </#list>
    }

<#list entityInfo.primaryKeys as field>
    public ${field.varType} get${field.varName?cap_first}() {
        return ${field.varName};
    }

    public void set${field.varName?cap_first}(${field.varType} ${field.varName}) {
        this.${field.varName} = ${field.varName};
    }

</#list>
<#if (config.useChainMode)>
    public Builder bind() {
        return new Builder(this);
    }

    public static Builder builder() {
        return new Builder();
    }

    public static class Builder {

    private final ${entityInfo.name?cap_first}PK targetPK;

    public Builder() {
        targetPK = new ${entityInfo.name?cap_first}PK();
    }

    public Builder(${entityInfo.name?cap_first}PK targetPK) {
        this.targetPK = targetPK;
    }

    public ${entityInfo.name?cap_first}PK build() {
        return targetPK;
    }

    <#list entityInfo.primaryKeys as field>

        public ${field.varType} ${field.varName}() {
            return targetPK.get${field.varName?cap_first}();
        }

        public Builder ${field.varName}(${field.varType} ${field.varName}) {
            targetPK.set${field.varName?cap_first}(${field.varName});
            return this;
        }
    </#list>
    }
</#if>
}
